<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" import="org.jdom.*,com.uft.utils.*,java.util.*"
	errorPage="error.jsp"
%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ page isELIgnored="false"%>


<script>
$( ".column" ).sortable({
    connectWith: ".column",
    handle: ".portlet-header",
    cancel: ".portlet-toggle",
    placeholder: "portlet-placeholder ui-corner-all"
  });
$( ".portlet" )
	.addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
	.find( ".portlet-header" )
	  .addClass( "ui-widget-header ui-corner-all" )
	  .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>");
$( ".portlet-toggle" ).click(function() {
		 var icon = $( this );
		 icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" );
	icon.closest( ".portlet" ).find( ".portlet-content" ).toggle();
});

var memoryDataObj =[];
updateMemoryDataObj();
drawMemoryUsageChart();


var intervalId = setInterval(function() {
	if($('#CurrentMemoryUsage').visible()){
		updateMemoryDataObj();
		drawMemoryUsageChart();
	}else{
		clearTimeout ( intervalId );
	}
	
},15000)
function updateMemoryDataObj(){
	$.ajaxq("plot",{
    	async: false,
		type: "POST",
		url: "getJVMRuntimeStats.htm",
	    dataType: 'json',
	    success: function( data ) {
	    	if(data){
	    		memoryDataObj.push(data);
	    	}
	    },
	    
	  }); 
}


function drawMemoryUsageChart(){
	var usedMemoryRenderer = function(){
		var data = [[],[],[]];
		for (var i = 0; i < memoryDataObj.length; i++ ) {
			 var memoryValues=memoryDataObj[i];
			 var date = new Date(memoryValues.genTimeStamp);
			 console.log(date);
			 data[0].push([date, memoryValues.usedMemory]);
			 data[1].push([date, memoryValues.freeMemory]);
			 data[2].push([date, memoryValues.totalMemory]);
		}
		 return data;
	}
	var plot1 = $.jqplot('jvmMemoryUsage',[],{
		title: 'Memory Usage',
	    dataRenderer: usedMemoryRenderer,
	    series:[
	            {
	            	 color:'#5FAB78',
	            	 markerOptions: { style:"circle" },
	            	 label: 'Used Memory'
	            },
	            {
	            	color:'#2A120A',
	            	 markerOptions: { style:'dimaond' },
	            	 label: 'Free Memory'
	            },
	            {
	            	lineWidth:1,
	            	color:'#FA5858',
	            	 label: 'Total Memory'
	            }
	            	
	          ],
	    axes:{
	    	xaxis:{
	    		renderer:$.jqplot.DateAxisRenderer,
	    		tickOptions:{
                    formatString:'%m/%d/%y %H:%M'
                },
	   			tickInterval:"30 minute",
	   			label:'Date',
	    	},
	    	yaxis:{
	            label:"Memory(MB)"   
	            
	          }
	    },
	    legend: {
	    	show: true,
	    	location: 'nw',
	    },
	    highlighter: {
	        show: true,
	        sizeAdjust: 7.5
	      },
	      cursor: {
	        show: false
	      }
	
	}).redraw(true);
	
}




</script>
<div class="column">

<div class="portlet" id="profileStatus">
	<div class="portlet-header">
		Profiles
	</div>
	<div class="portlet-content">
		<table>
			<tr><td>Available Profiles: <td><td>1</td></tr>
			<tr><td>Profiles Currently Active: <td><td>1</td></tr>
		</table>
	</div>
</div>
<div class="portlet" id="Deployments">
<div class="portlet-header">
		Deployments
	</div>
	<div class="portlet-content">
		<table>
			<tr><td>Active Deployments: <td><td>1</td></tr>
			<tr><td>Schedule Deployments<td><td>1</td></tr>
		</table>
	</div>
</div>

<div class="portlet" id="Configuration">
	<div class="portlet-header">
		Configuration
	</div>
	<div class="portlet-content">
		<table>
			<tr><td>Active Configuration: <td><td>1</td></tr>
			<tr><td>Schedule Configuration: <td><td>1</td></tr>
		</table>
	</div>
</div>

<sec:authorize ifAllGranted="ROLE_ADMIN">

<div class="portlet" id="Users">
	<div class="portlet-header">
		Users
	</div>
	<div class="portlet-content">
		<table>
			<tr><td>User Current logged: <td><td>1</td></tr>
		</table>
	</div>
</div>
<div class="portlet" id="Audit">
	<div class="portlet-header">
		Audit
	</div>
	<div class="portlet-content">
		Once Day Audit
		<table>
			<tr><td>User Current logged: <td><td>1</td></tr>
		</table>
	</div>
</div>

</sec:authorize>
</div>
<div class="column">
<div class="portlet" id="CurrentMemoryUsage">
	<div class="portlet-header">
		Current Memory Usage
	</div>
	<div class="portlet-content">
		<div id="jvmMemoryUsage">
			
		</div>	
	</div>

</div>
</div>